package com.tedu.ds.equipment.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tedu.ds.base.response.JsonResult;
import com.tedu.ds.equipment.pojo.dto.EquipmentParam;
import com.tedu.ds.equipment.pojo.dto.EquipmentQuery;
import com.tedu.ds.equipment.service.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/equipment")
@Api(tags = "设备信息模块")
public class EquipmentController {
    @Autowired
    private EquipmentService equipmentService;

    @PostMapping("/select")
    @ApiOperation("查询功能")
    public JsonResult select(@RequestBody EquipmentQuery equipmentQuery){
        return JsonResult.ok(equipmentService.select(equipmentQuery));
    }

    @PostMapping("/save")
    @ApiOperation("新增和更新功能")
    public JsonResult save(@RequestBody @Validated EquipmentParam equipmentParam){
        equipmentService.save(equipmentParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除功能")
    @ApiImplicitParam(name = "id",value = "设备id",required = true)
    public JsonResult delete(@PathVariable Long id){
        equipmentService.delete(id);
        return JsonResult.ok();
    }
}
